package com.cn.kabalifeuser.ui.login;

import android.content.Context;
import android.graphics.Rect;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.core.widget.NestedScrollView;

import com.cn.kabalifeuser.R;
import com.cn.kabalifeuser.base.BasePresenter;
import com.cn.kabalifeuser.base.IBaseActivity;
import com.cn.kabalifeuser.ui.login.bean.AgreementBean;
import com.cn.kabalifeuser.utils.LoggerUtils;
import com.cn.kabalifeuser.utils.WebViewHtmlUtils;
import com.zzhoujay.richtext.RichText;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 项目：KaBaLifeUser
 * 包名：com.cn.kabalifeuser.ui.login
 * 类名：AgreementActivity2
 * 创建时间：2020/11/30 4:56 PM
 * 创建人 @author： xiaolin
 * 描述 ：Todo...
 */
public class AgreementActivity2 extends IBaseActivity<AgreementView, AgreementPresenter> implements AgreementView {
    @BindView(R.id.tv_details)
    TextView tvDetails;
    @BindView(R.id.scrollView)
    NestedScrollView scrollView;
    @BindView(R.id.tv_btn_no)
    TextView tvBtnNo;
    @BindView(R.id.tv_btn_yes)
    TextView tvBtnYes;
    @BindView(R.id.ll_b)
    LinearLayout llB;
    Bundle bundle;
    int sign;
    @Override
    protected AgreementPresenter createPresenter() {
        return new AgreementPresenter();
    }

    @Override
    protected int provideContentViewId() {
        return R.layout.activity_h52;
    }

    @Override
    public void initView(Bundle savedInstanceState) {
        super.initView(savedInstanceState);
        bundle = getIntent().getExtras();
        sign = bundle.getInt("sign");
        if (sign == 1)
            setTitleBar("注册协议");

        scrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
            @Override
            public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {

                //Log.e(TAG, "onScrollChange: " + scrollX +"---" + scrollY + "----" +oldScrollX + "---" + oldScrollY );
                //监听滚动状态

                if (scrollY > oldScrollY) {//向下滚动
                    LoggerUtils.e( "Scroll DOWN");
                }
                if (scrollY < oldScrollY) {//向上滚动
                    LoggerUtils.e(  "Scroll UP");
                }

                if (scrollY == 0) {// 滚动到顶
                    LoggerUtils.e(  "TOP SCROLL");
                }
                // 滚动到底
                if (scrollY == (v.getChildAt(0).getMeasuredHeight() - v.getMeasuredHeight())) {
                    LoggerUtils.e(  "BOTTOM SCROLL");
                }

                //判断某个控件是否可见
//                Rect scrollBounds = new Rect();
//                scrollView.getHitRect(scrollBounds);
//                if (scrollView.getLocalVisibleRect(scrollBounds)) {//可见
//                    LoggerUtils.e( "onScrollChange:  第3个可见" );
//                }else {//完全不可见
//                    LoggerUtils.e(  "onScrollChange:  第3个不可见" );
//                }



//                Log.e(TAG, "onScrollChange: ------------" + scrollY +"------"+ tvscrollthree.getTop() );
//                //判断某个控件是否滚到顶部
//                if (scrollY == tvscrollthree.getTop()){
//                    Log.i(TAG, "onScrollChange: ------top-------" );
//                }
//
//                Log.e(TAG, "onScrollChange: bottmo" + scrollY +"-----"+ (tvscrollthree.getTop() + tvscrollthree.getHeight()) );


            }
        });

    }

    @OnClick({R.id.tv_btn_no, R.id.tv_btn_yes})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_btn_no:
                break;
            case R.id.tv_btn_yes:
                break;
        }
    }

    @Override
    public void onReLoggedIn(String msg) {

    }

    @Override
    public void onError(String msg) {

    }

    @Override
    public Context _getContext() {
        return null;
    }

    @Override
    public void onAgreementSuccess(AgreementBean bean) {
        if (!TextUtils.isEmpty(bean.getResult())) {
//            RichText.fromHtml(bean.getResult()).autoFix(false).showBorder(false).autoPlay(true).into(tvDetails);
            RichText.from(bean.getResult()).bind(this).into(tvDetails);
        }
    }
}
